#ifndef		_MUtils_
#define		_MUtils_
//-------------------------------------------------------------------------------------------------------
//      Copyright (c) 2005-2009, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:   	MUtils.h
//      Author:      	Be Nanashi-San@598 in "BeOS - Zeta R4" Thread 
//						(http://pc8.2ch.net/test/read.cgi/os/1120676818/598)
//		Description:	MStyle, MActionList 小物Class.
//-------------------------------------------------------------------------------------------------------

#include <Font.h>
#include <TextView.h>		// for text_run_array
#include <stdlib.h>
#include <vector>

enum action_type{
	ACTION_MAIL,
	ACTION_AGE,
	ACTION_SAGE,
	ACTION_JMP_THREAD,
	ACTION_JMP_URL,
	ACTION_JMP_BBS,
	ACTION_TEST
};

struct action_info {
	action_info():name(NULL){};
	~action_info(){if (name) ::free(const_cast<char *>(name));};
	
	int32 offset;			// actionのoffset位置
	int32 length;			// offset位置からのlength(actionの有効範囲)
	const char *name ;		// action名
	int32 size;				// nameの長さ
	action_type type;
};

// ==M=S=t=y=l=e======================================
class MStyle
{
public:
	MStyle(){
		fTextArray.count = 1;
		fTextArray.runs[0].offset = 0;
	}
	const text_run_array* TextRunArray(){
		return &fTextArray;
	}

	void SetFont(BFont &font){
		fTextArray.runs[0].font = font;
	}

	void SetColor(const uint8 r, const uint8 g, const uint8 b){
		fTextArray.runs[0].color.red = r;
		fTextArray.runs[0].color.green = g;
		fTextArray.runs[0].color.blue = b;
		fTextArray.runs[0].color.alpha = 0;
	}
	protected:
		text_run_array fTextArray;	
};


// ==M=A=c=t=i=o=n=l=i=s=t============================
class MActionList{
	public:
	MActionList(BTextView *target);
	~MActionList();
	void Clear();
	void AddAction(action_info*);
	action_info* ItemTo(int32 offset);
	const action_info* Current() { return fAction;};

	private:
	BTextView*	fTarget;
	action_info *fAction;
	std::vector<action_info *> fActionArray; 
};

#endif
